﻿using System;
using System.Globalization;
using System.Web.UI.WebControls;

namespace DotNetNuke.Modules.UserDefinedTable
{


  public class EditDecimal : EditString
  {



    //public EditDecimal()
    //{
    //  base.Init += new EventHandler(this.EditDecimal_Init);
    //}

    protected override void OnInit(EventArgs e)
    {
      base.OnInit(e);
      //base.Init += new EventHandler(this.EditDecimal_Init);
      base.ctlValueBox.Attributes.Add("style", "text-align:right");
      Unit unit2 = new Unit("10em");
      base.ctlValueBox.Width = unit2;
    }




    //private void EditDecimal_Init(object sender, EventArgs evt)
    //{
    //  base.ctlValueBox.Attributes.Add("style", "text-align:right");
    //  Unit unit2 = new Unit("10em");
    //  base.ctlValueBox.Width = unit2;
    //}




    protected override bool IsValidType()
    {
      decimal num;
      if (!string.IsNullOrEmpty(this.Value) && !decimal.TryParse(this.Value, out num))
        return false;
      
      return true;
    }




    public override string Value
    {
      get
      {
        string str;
        try
        {
          str = string.Empty;
          CultureInfo provider = new CultureInfo("en-US");
          if ( !string.IsNullOrEmpty(base.Value) )
            str = int.Parse(base.Value).ToString(provider);

        }
        catch (Exception e)
        {
          str = base.Value;
        }
        return str;
      }
      set
      {
        CultureInfo provider = new CultureInfo("en-US");
        if (value != "")
          value = decimal.Parse(value, provider).ToString("#,###,###,##0.####");

        base.Value = value;
      }
    }


  }

}

